/*
 Sample code for the BH1750 Light sensor
 Version 0.1
 website:www.DFRobot.com
  
 Connection:
  
 VCC-5v
 GND-GND
 SCL-SCL(analog pin 5)
 SDA-SDA(analog pin 4)
 ADD-NC
 */
 
 
#include <Wire.h> //BH1750 IIC Mode
int BH1750address = 0x23; //setting i2c address
 
byte buff[2];
void setupSensor()
{
  Wire.begin();
  BH1750_Init(BH1750address);
}
 
int BH1750_Read() //
{
  uint16_t val=0;
  int i=0;
  Wire.beginTransmission(BH1750address);
  Wire.requestFrom(BH1750address, 2);
  while(Wire.available()) //
  {
    buff[i] = Wire.read();  // receive one byte
    i++;
  }
  Wire.endTransmission(); 
  
  if(i==2)
  {
    val=((buff[0]<<8)|buff[1])/1.2;
  }
  return val;
}
 
void BH1750_Init(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x10);//1lx reolution 120ms
  Wire.endTransmission();
  delay(200);
}
